<template>
  <div class="landUse">
    <div class="top-box">
      <div class="top-box-item" v-for="(i, k) in topList" :key="k">
        <img class="img" :src="i.icon" />
        <div class="info">
          <div class="label">{{ i.name }}</div>
          <div class="value">
            <CountTo :startVal="0" :endVal="i.value" :duration="1000" />
            <span class="unit">{{ i.unit }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="second-title">全市工业用电趋势分析</div>
    <div id="chart2" class="chart-box"></div>
  </div>
</template>
<script>
import lightling from '@/assets/industrialOperation/lioghtning.png'
import house from '@/assets/industrialOperation/house.png'
import * as echarts from 'echarts'
import CountTo from 'vue-count-to'

export default {
  name: '',
  components: {
    CountTo
  },
  data() {
    return {
      topList: [
        {
          name: '本周工业用电总量',
          value: '750',
          unit: '万千瓦时',
          icon: lightling
        },
        {
          name: '本周重点企业用电量',
          value: '750',
          unit: '万千瓦时',
          icon: house
        }
      ]
    }
  },
  mounted() {
    this.initFun()
  },
  methods: {
    initFun() {
      let option = {
        legend: {
          show: false
        },
        tooltip: {
          trigger: 'axis',
          extraCssText:
            'background: #fff; border-radius: 0;box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);color: #333;',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          top: '25%',
          left: '0%',
          right: '0%',
          bottom: '0%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: true,
            axisLabel: {
              textStyle: {
                color: '#F2F6FF'
              }
            },
            axisTick: {
              show: false // 不显示坐标轴刻度线
            },
            axisLine: {
              lineStyle: {
                color: '#00BAFF'
              }
            },
            data: [
              '1月',
              '2月',
              '3月',
              '4月',
              '5月',
              '6月',
              '7月',
              '8月',
              '9月',
              '10月',
              '11月',
              '12月'
            ]
          }
        ],
        yAxis: [
          {
            name: '单位：亿千瓦时',
            type: 'value',
            axisLabel: {
              textStyle: {
                color: '#F2F6FF'
              }
            },
            nameTextStyle: {
              color: '#F2F6FF',
              fontSize: 12,
              padding: [0, 0, 0, 30]
            },
            splitLine: {
              lineStyle: {
                type: 'solid',
                color: 'rgba(0, 186, 255, 0.57)'
              }
            },
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: [
          {
            name: '',
            type: 'line',
            color: '#55D297',
            symbolSize: 7,
            areaStyle: {
              normal: {
                color: {
                  type: 'linear',
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: 'rgba(85, 210, 151, 0.8)'
                    },
                    {
                      offset: 1,
                      color: 'rgba(85, 210, 151, 0.2)'
                    }
                  ]
                }
              }
            },
            data: [100, 140, 155, 160, 180, 200, 210, 150, 180, 160, 140, 180]
          }
        ]
      }
      const lineObj = echarts.init(document.getElementById('chart2'))
      lineObj.setOption(option)
    }
  }
}
</script>
<style lang="scss" scoped>
.landUse {
  display: flex;
  flex-direction: column;
  .top-box {
    display: flex;
    .top-box-item {
      flex: 1;
      display: flex;
      .img {
        width: 51px;
        height: 48px;
      }
      .info {
        display: flex;
        flex-direction: column;
        .label {
          font-family: MicrosoftYaHeiUI;
          font-size: 16px;
          color: #ffffff;
          padding-left: 7px;
        }
        .value {
          display: flex;
          font-family: SourceHanSansSC, SourceHanSansSC;
          font-weight: bold;
          font-size: 20px;
          color: #ffde00;
          padding-left: 7px;
          .unit {
            font-family: MicrosoftYaHeiUI;
            font-size: 14px;
            color: #ffffff;
            transform: translateY(5px);
            margin-left: 5px;
          }
        }
      }
    }
  }
  .second-title {
    width: 100%;
    height: 31px;
    display: flex;
    align-items: center;
    padding-left: 20px;
    font-family: MicrosoftYaHeiUI;
    font-size: 16px;
    font-weight: bold;
    color: #ffffff;
    margin-top: 14px;
    background: url('~@/assets/industrialOperation/second-title.png') center
      center/cover;
  }
  .chart-box {
    flex: 1;
  }
}
</style>
